/**
 * Created by hubin on 2016/6/14.
 */

var Topic_vm = avalon.define({
    $id: "topic",
    pageSize: 6,
    pageCurrent: 1,
    pageTotle: 0,
    topiclist: {},
    keyword: "",
    topicItem: {id: 0, createTime: "", content: "", title: "", userID: 0},
    uptatetopic: {},
    <!-- 获取理产品列表-->
    getTopicList: function () {
        $.ajax({
            type: 'POST',
            url: '/CounterDrops/topic/gettopiclist',
            data: {
                pageSize: Topic_vm.pageSize,
                pageCurrent: Topic_vm.pageCurrent,
                keyword: Topic_vm.keyword
            },
            success: function (data) {
                Topic_vm.topiclist = data.model.results;
                Topic_vm.pageTotle = data.model.totalPage;
            },
            error: function (e) {

            }
        });
        $('#addTime').datepicker({startDate: '2015-5-5', format: 'yyyy-mm-dd'});
    },
    cheak: function () {
        Topic_vm.pageCurrent = 1;
        Topic_vm.getTopicList();
    },

    firstPage: function () {
        Topic_vm.pageCurrent = 1;
        Topic_vm.getTopicList();
    },
    lastPage: function () {
        Topic_vm.pageCurrent = product_vm.pageTotle;
        Topic_vm.getTopicList();
    },
    previousPage: function () {
        if (Topic_vm.pageCurrent == 1) {
            swal("当前为第一页!");
            return;
        }
        Topic_vm.pageCurrent--;
        Topic_vm.getTopicList();

    },
    nextPage: function () {
        if (Topic_vm.pageCurrent == Topic_vm.pageTotle) {

            swal("当前为最后一页!");
            return;
        }
        Topic_vm.pageCurrent++;
        Topic_vm.getTopicList();
    },
    showupdatetopic: function (el) {
        Topic_vm.uptatetopic = el;
        Topic_vm.uptatetopic.createTime = new Date(el.createTime).toString("yyyy-MM-dd");
        $('#updatetopicModel').modal('show');
    },

    addTopic: function () {
        $.ajax({
            type: 'POST',
            url: '/CounterDrops/topic/addtopic',
            data: {
                title: Topic_vm.topicItem.title,
                createTime: Topic_vm.topicItem.createTime,
                content: Topic_vm.topicItem.content,
            },
            success: function (data) {

                if (data.success == true) {
                    swal("添加成功!");
                } else {
                    swal("添加失败!");
                }
                $('#myModal').modal('hide');
                Topic_vm.getTopicList();
            },
            error: function (e) {
                swal("添加失败!");
            }
        })
    },
    updateTopic: function () {
        $.ajax({
            type: 'POST',
            url: '/CounterDrops/topic/updatetopic',
            data: {
                title: Topic_vm.uptatetopic.title,
                content: Topic_vm.uptatetopic.content,
                id: Topic_vm.uptatetopic.id,
            },
            success: function (data) {
                if (data.success == true) {
                    swal("修改成功!");
                } else {
                    swal("修改失败!");
                }
                $('#updatetopicModel').modal('hide');
                Topic_vm.getTopicList();
            },
            error: function (e) {

            }
        })
    },
    delTopic: function () {
        $.ajax({
            type: 'GET',
            url: '/CounterDrops/topic/deltopic',
            data: {
                id: Topic_vm.uptatetopic.id,
            },
            success: function (data) {

                if (data.success == true) {
                    swal("删除成功!");
                } else {
                    swal("删除失败!");
                }
                $('#updatetopicModel').modal('hide');
                Topic_vm.getTopicList();
            },
            error: function (e) {

            }
        })
    },
});
Topic_vm.getTopicList();